Polymorphism : Overriding vs Overloading

  • Note

    What is Polymorphism ?

    It is a feature of OOPS

    It helps to define same function name with different signature

    Type of Polymorphism

    Overloading: (use in same class)

    Same function name with different signature in same class

    Overriding: (use in two classes )

    Same function name in parent and child classes

    How does help

    Maintainability:

    Suppose we extend and reuse the parent class functions in child classes. Sometimes we want to change the logic of the parent class function for a particular child class (not for all child classes). If we change in the parent class, that change will also affect the other child classes

    Polymorphism helps the developer to define the same function name in the child class and implement the new logic for that particular class without affect the otehr child classes